/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ia_0.data_model.actions;

import ia_0.Move;
import ia_0.World;
import ia_0.data_model.character.Character;
import java.awt.Point;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author jderenty
 */
public abstract class Action {

    public void raz() {
        termine=false;
        commence=false;
    }

    public abstract boolean toDo();
    public abstract void doIt();

    public boolean commence=false;
    private boolean termine=false;

    Character c;
    public Move m;

    public Action(Character c){
        this.c=c;
    }


    public void setCommence(){
        commence=true;
        termine=false;
    }

    public boolean getCommence(){
        Point p =World.elements.get(this.c);
        if(this.commence && m!=null && m.courant!=null && !p.equals(m.courant)){
            m=new Move(c, m.dest);
        }
        return this.commence;
    }

    public void setTermine(){
        termine=true;
        commence=false;
        if(nb!=null){
            setTimer(nb);
        }
    }

    public boolean getTermine(){
        return termine;
    }



    boolean endTimer=false;
    public boolean toDoTimer(){
        boolean res=endTimer;
        this.endTimer=false;
        return res;
    }



    Integer nb;
    public void setTimer(int nb){
        this.nb=nb;
        endTimer=false;
        try{
            TimerTask action = new TimerTask() {
                @Override
                public void run() {
                    endTimer=true;
                }
            };

            new Timer().schedule(action, nb, nb);

        } catch(Exception e){
            System.out.println("déja schédulé");
        }


        }
    








}
